MkMetadataBadges
Container node for a list of metadata badges.
Note
Description
Badges are generated locally using “anybadge” package
Examples
Example: Classifiers
Note
Jinja
{{ "classifiers" | MkMetadataBadges }}
Note
Python
MkMetadataBadges('classifiers')
Rendered
Markdown












Html
Example: Keywords
Note
Jinja
{{ "keywords" | MkMetadataBadges }}
Note
Python
MkMetadataBadges('keywords')
Rendered
Markdown








Html
Example: Keywords combined
Note
Jinja
{{ "keywords_combined" | MkMetadataBadges }}
Note
Python
MkMetadataBadges('keywords_combined')
Rendered
Markdown

Html
<p><img src="https://img.shields.io/badge/Keywords-blue" alt="Keywords" /></p>
Repr tree
MkMetadataBadges
╰── MkBadge('Keywords', 'api-documentation | docs-as-code | documentation | documentation-generator | jinja2 | markdown | static-site-generator | zensical')
Example: Websites
Note
Jinja
{{ "websites" | MkMetadataBadges }}
Note
Python
MkMetadataBadges('websites')
Markdown
[](https://app.codecov.io/gh/phil65/mknodes)
[](https://github.com/phil65/mknodes/discussions)
[](https://phil65.github.io/mknodes/)
[](https://github.com/phil65/mknodes/issues)
[](https://github.com/phil65/mknodes)
Html
Example: Dependencies
Note
Jinja
{{ "dependencies" | MkMetadataBadges }}
Note
Python
MkMetadataBadges('dependencies')
Markdown
[](https://github.com/jongracecox/anybadge)
[](https://phil65.github.io/anyenv/)
[](https://anyio.readthedocs.io/en/latest/)
[](https://phil65.github.io/clinspector/)
[](https://github.com/facelessuser/coloraide)
[](https://github.com/phil65/epregistry)
[](https://github.com/pyapp-kit/fieldz)
[](https://github.com/fsspec/filesystem_spec)
[](https://pawamoy.github.io/git-changelog)
[](https://github.com/phil65/githarbor)
[](https://gitpython.readthedocs.io/en/stable/)
[](https://mkdocstrings.github.io/griffe)
[](https://jinja.palletsprojects.com/)
[](https://phil65.github.io/jinjarope/)
[](https://pydantic.dev/logfire)
[](https://Python-Markdown.github.io/)
[](https://markupsafe.palletsprojects.com/)
[](https://github.com/SethMMorton/natsort)
[](https://packaging.pypa.io/)
[](https://github.com/tox-dev/pipdeptree)
[](https://github.com/tox-dev/platformdirs)
[](https://github.com/pydantic/pydantic)
[](https://github.com/facelessuser/pymdown-extensions)
[](https://github.com/pytest-dev/pytest-asyncio)
[](https://github.com/theskumar/python-dotenv)
[](https://pyyaml.org/)
[](https://requests.readthedocs.io)
[](https://github.com/Textualize/rich)
[](https://github.com/hukkin/tomli-w)
[](https://github.com/fastapi/typer)
[](https://github.com/fsspec/universal_pathlib)
[](https://phil65.github.io/upathtools/)
[](https://phil65.github.io/yamling/)
[](https://zensical.org/)
[](https://github.com/executablebooks/markdown-it-py)
[](https://github.com/executablebooks/mdit-py-plugins)
[](https://phil65.github.io/mkconvert/)
[](https://phil65.github.io/agentpool/)
[](https://www.mkdocs.org/)
[](https://squidfunk.github.io/mkdocs-material/)

[](https://github.com/executablebooks/MyST-Parser)
[](https://www.sphinx-doc.org/)
[](https://github.com/executablebooks/sphinx-design)
Html
Example: For other packages
Note
Jinja
{{ "dependencies" | MkMetadataBadges(package="mkdocs") }}
Note
Python
MkMetadataBadges('dependencies', package='mkdocs')
Markdown
[](https://click.palletsprojects.com/)
[](https://github.com/tartley/colorama)
[](https://github.com/c-w/ghp-import)
[](https://jinja.palletsprojects.com/)
[](https://Python-Markdown.github.io/)
[](https://markupsafe.palletsprojects.com/)
[](https://github.com/clarketm/mergedeep)
[](https://github.com/mkdocs/get-deps)
[](https://packaging.pypa.io/)
[](https://python-path-specification.readthedocs.io/en/latest/index.html)
[](https://github.com/waylan/pyyaml-env-tag)
[](https://pyyaml.org/)
[](https://github.com/gorakhargosh/watchdog)
[](https://babel.pocoo.org/)
Html
<p><a href="https://click.palletsprojects.com/"><img src="https://img.shields.io/badge/click-8.5.1-blue" alt="click: 8.5.1" /></a>
<a href="https://github.com/tartley/colorama"><img src="https://img.shields.io/badge/colorama-0.4.6-blue" alt="colorama: 0.4.6" /></a>
<a href="https://github.com/c-w/ghp-import"><img src="https://img.shields.io/badge/ghp--import-2.1.0-blue" alt="ghp-import: 2.1.0" /></a>
<a href="https://jinja.palletsprojects.com/"><img src="https://img.shields.io/badge/Jinja2-3.1.6-blue" alt="Jinja2: 3.1.6" /></a>
<a href="https://Python-Markdown.github.io/"><img src="https://img.shields.io/badge/Markdown-3.11.4-blue" alt="Markdown: 3.11.4" /></a>
<a href="https://markupsafe.palletsprojects.com/"><img src="https://img.shields.io/badge/MarkupSafe-3.0.4-blue" alt="MarkupSafe: 3.0.4" /></a>
<a href="https://github.com/clarketm/mergedeep"><img src="https://img.shields.io/badge/mergedeep-1.3.4-blue" alt="mergedeep: 1.3.4" /></a>
<a href="https://github.com/mkdocs/get-deps"><img src="https://img.shields.io/badge/mkdocs--get--deps-0.2.2-blue" alt="mkdocs-get-deps: 0.2.2" /></a>
<a href="https://packaging.pypa.io/"><img src="https://img.shields.io/badge/packaging-26.4-blue" alt="packaging: 26.4" /></a>
<a href="https://python-path-specification.readthedocs.io/en/latest/index.html"><img src="https://img.shields.io/badge/pathspec-1.1.1-blue" alt="pathspec: 1.1.1" /></a>
<a href="https://github.com/waylan/pyyaml-env-tag"><img src="https://img.shields.io/badge/pyyaml__env__tag-1.1-blue" alt="pyyaml_env_tag: 1.1" /></a>
<a href="https://pyyaml.org/"><img src="https://img.shields.io/badge/PyYAML-6.0.4-blue" alt="PyYAML: 6.0.4" /></a>
<a href="https://github.com/gorakhargosh/watchdog"><img src="https://img.shields.io/badge/watchdog-7.1.1-blue" alt="watchdog: 7.1.1" /></a>
<a href="https://babel.pocoo.org/"><img src="https://img.shields.io/badge/babel-2.19.0-blue" alt="babel: 2.19.0" /></a></p>
Repr tree
MkMetadataBadges
├── MkBadge('click', '8.5.1')
├── MkBadge('colorama', '0.4.6')
├── MkBadge('ghp-import', '2.1.0')
├── MkBadge('Jinja2', '3.1.6')
├── MkBadge('Markdown', '3.11.4')
├── MkBadge('MarkupSafe', '3.0.4')
├── MkBadge('mergedeep', '1.3.4')
├── MkBadge('mkdocs-get-deps', '0.2.2')
├── MkBadge('packaging', '26.4')
├── MkBadge('pathspec', '1.1.1')
├── MkBadge('pyyaml_env_tag', '1.1')
├── MkBadge('PyYAML', '6.0.4')
├── MkBadge('watchdog', '7.1.1')
╰── MkBadge('babel', '2.19.0')
Example: Gitlab style
Note
Jinja
{{ "classifiers" | MkMetadataBadges(use_gitlab_style=True) }}
Note
Python
MkMetadataBadges('classifiers', use_gitlab_style=True)
Rendered
Markdown












Html
Example: Colored
Note
Jinja
{{ "required_python" | MkMetadataBadges(badge_color="red") }}
Note
Python
MkMetadataBadges('required_python', badge_color='red')
Markdown
[](https://python.org)
Html
<p><a href="https://python.org"><img src="https://img.shields.io/badge/Python-red" alt="Python" /></a></p>
Repr tree
MkMetadataBadges
╰── MkBadge('Python', '>=3.14', badge_color='red')
Base classes
| Name | Children | Inherits |
|---|---|---|
| MkContainer mknodes.basenodes.mkcontainer A node containing other MkNodes. |
⋔ Inheritance diagram
graph TD
4160346072["mkmetadatabadges.MkMetadataBadges"]
835538629["mkcontainer.MkContainer"]
1956333208["mkcontainer.MkContainerBase"]
1359323199["mknode.MkNode"]
2751680898["builtins.object"]
835538629 --> 4160346072
1956333208 --> 835538629
1359323199 --> 1956333208
2751680898 --> 1359323199
NodeFile
/home/runner/work/mknodes/mknodes/src/mknodes/templatenodes/mkmetadatabadges/metadata.toml
[metadata]
name = "MkMetadataBadges"
icon = "simple-icons:shieldsdotio"
status = "new"
group = "badge"
virtual_children = true
[requirements.package.anybadge]
[examples.classifiers]
title = "Classifiers"
jinja = """
{{ "classifiers" | MkMetadataBadges }}
"""
[examples.keywords]
title = "Keywords"
jinja = """
{{ "keywords" | MkMetadataBadges }}
"""
[examples.keywords_combined]
title = "Keywords combined"
jinja = """
{{ "keywords_combined" | MkMetadataBadges }}
"""
[examples.websites]
title = "Websites"
jinja = """
{{ "websites" | MkMetadataBadges }}
"""
[examples.dependencies]
title = "Dependencies"
jinja = """
{{ "dependencies" | MkMetadataBadges }}
"""
[examples.other_packages]
title = "For other packages"
jinja = """
{{ "dependencies" | MkMetadataBadges(package="mkdocs") }}
"""
[examples.gitlab]
title = "Gitlab style"
jinja = """
{{ "classifiers" | MkMetadataBadges(use_gitlab_style=True) }}
"""
[examples.colored]
title = "Colored"
jinja = """
{{ "required_python" | MkMetadataBadges(badge_color="red") }}
"""
[output.markdown]
template = """
{% filter rstrip %}
{% for label, value, link in node.badge_content %}
{{ label | MkBadge(value=value, target=link, font_size=node.font_size, font_name=node.font_name, badge_color=node.badge_color, text_color=node.text_color, num_padding_chars=node.num_padding_chars, use_gitlab_style=node.use_gitlab_style, title=label) }}
{% endfor %}
{% endfilter %}
"""
Code
mknodes.templatenodes.mkmetadatabadges.MkMetadataBadges
class MkMetadataBadges(mkcontainer.MkContainer):
"""Container node for a list of metadata badges.
Badges are generated locally using "anybadge" package
"""
ICON = "simple/shieldsdotio"
STATUS = "new"
VIRTUAL_CHILDREN = True
def __init__(
self,
typ: datatypes.MetadataTypeStr,
*,
package: str | None = None,
font_size: Literal[10, 11, 12] | None = None,
font_name: str | None = None,
num_padding_chars: int | None = None,
badge_color: str | None = None,
text_color: str | None = None,
use_gitlab_style: bool = False,
block_separator: str = "\n",
**kwargs: Any,
) -> None:
"""Constructor.
Args:
typ: Metadata badges to show
package: Package to show badges for. If None, it will get pulled from project
font_size: Size of font to use
font_name: Name of font to use
num_padding_chars: Number of chars to use for padding
badge_color: Badge color. If none is set, it will be pulled from project.
text_color: Badge color
use_gitlab_style: Use Gitlab-scope style
block_separator: Divider to use between badges
kwargs: Keyword arguments passed to parent
"""
super().__init__(block_separator=block_separator, **kwargs)
self._package = package
self.typ = typ
self.font_size: Literal[10, 11, 12] | None = font_size
self.font_name = font_name
self.num_padding_chars = num_padding_chars
self.badge_color = badge_color
self.text_color = text_color
self.use_gitlab_style = use_gitlab_style
@property
def badge_content(self) -> list[tuple[str, str | None, str | None]]: # noqa: PLR0911
ctx = packageregistry.get_info(self._package) if self._package else self.ctx.metadata
match self.typ:
case "classifiers":
items: list[tuple[str, str | None, str | None]] = []
for category, labels in ctx.classifier_map.items():
items.extend([(i, category, None) for i in labels])
return items
case "keywords":
return [(keyword, "", None) for keyword in ctx.keywords]
case "keywords_combined":
return [("Keywords", " | ".join(ctx.keywords), None)]
case "required_python":
return [("Python", ctx.required_python_version, "https://python.org")]
case "websites":
return [(name, parse.urlparse(url).netloc, url) for name, url in ctx.urls.items()]
case "dependencies":
return [(p.name, p.version, p.homepage) for p in ctx.required_packages]
case "installed_packages":
return [
(p.name, p.version, p.homepage)
for p in packageregistry.get_installed_packages()
]
case str():
raise ValueError(self.typ)
case _ if self.typ in datatypes.CLASSIFIERS:
labels = ctx.classifier_map.get(self.typ, [])
return [(i, self.typ, None) for i in labels]
def get_items(self) -> list[mknode.MkNode]:
"""Return computed badge items."""
return [
mkbadge.MkBadge(
label=label,
value=value,
target=link,
font_size=self.font_size,
font_name=self.font_name,
badge_color=self.badge_color,
text_color=self.text_color,
num_padding_chars=self.num_padding_chars,
use_gitlab_style=self.use_gitlab_style,
title=label,
parent=self,
)
for label, value, link in self.badge_content
]
Page info
Code for this page
mknodes.manual.nodes_section.create_section_for_nodes
def create_section_for_nodes(
nav: mk.MkNav,
klasses: Sequence[type[mk.MkNode]],
) -> mk.MkTable:
table = mk.MkTable(columns=["Node", "Docstrings", "Markdown extensions"])
for kls in klasses:
tpl = "classpage_custom.jinja"
page = mk.MkClassPage(kls, icon=kls.ICON, template_path=tpl, parent=nav, hide="toc")
nav += page
if kls.STATUS:
page.metadata.status = kls.STATUS
elif kls.JS_FILES:
page.metadata.status = "js"
elif kls.CSS:
page.metadata.status = "css"
page.created_by = create_section_for_nodes
link = mk.MkLink(page, kls.__name__, icon=kls.ICON)
extensions = ", ".join(f"`{i}`" for i in kls.REQUIRED_EXTENSIONS)
table.add_row((link, kls.__doc__, extensions))
return table
Resources
Resources(css=[],
markdown_extensions={'admonition': {},
'pymdownx.details': {},
'pymdownx.highlight': {'anchor_linenums': True,
'line_spans': '__span',
'pygments_lang_class': True},
'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
'format': <function fence_code_format at 0x7d707a397060>,
'name': 'mermaid'}]},
'pymdownx.tabbed': {},
'tables': {}},
plugins=[Plugin('mkdocstrings')],
js=[],
assets=[],
packages=[])
Metadata
created:
source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/nodes_section.py
source_function: create_section_for_nodes
source_line_no: 93
hide:
- toc
icon: simple/shieldsdotio
status: new
title: MkMetadataBadges